<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title> 家計簿　</title>
    <script type="text/javascript" src="js/prototype-1.6.0.3.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/dateselect.js"></script>
    <script type="text/javascript" src="js/category.js"></script>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/account.css" rel="stylesheet" type="text/css">
  </head>
<body>
  {% include "_menu.html" %}
  <h3>家計簿　データ編集</h3>
  <form id="account" action="/updateAccount" method="post">
    <div>
        <div id="account_date">
        </div>
        <div>
           <span class="title" id="items_span"></span>
         </div>
          <div id="price_div">
            <span class="title">費用</span>
            <input type="text" value={{account.price}} name="price" id="account_price" size="30" style="{ime-mode : disabled}"/>
            <input type="hidden" value={{account.key}} name="key" />
            <input type="button" tabindex=-1 value="計算" onclick="calculate();return false;"/>
            <br>
            <span class="mini">+(足す)-(引く)*(掛ける)/(割る)()カッコを使って計算を押すと計算結果に変わります</span>
          </div>
      </div>
    </div>
    <div class="bottom"><span class="title">内容</span>
      <input type="text" size="100" value="{{account.content}}" id="account_content" name="content" style="vertical-align:top"/>
    </div>
    <input type="submit" value="更新" onclick="return checkData()"/>
    <input type="button" value="キャンセル" onclick="cancelAccount()"/>
  </form>
  <script type="text/javascript">
    var year={{account.date.year}};
    var month={{account.date.month}};
    var day={{account.date.day}};
    var category="{{account.category.name}}";
    function cancelAccount()
    {
      history.back();
    }
    function calculate()
    {
      if($F('account_price').match(/^[\d\.\+\-\*\/()]+$/))
      {
        var result;
        eval("result="+$F('account_price'));
        $('account_price').value=parseInt(result,10);
      }
      else
      {
        alert("計算式として認識できない文字があります。");
      }
    }
    function checkData()
    {
      if($F("account_price")=="")
      {
        alert("費用が入力されていません。");
        return false;
      }
      if($F("account_price").match(/\D/))
      {
        alert("費用に数字以外の文字が含まれています");
        return false;
      }
      if(!$F("account_content"))
      {
        alert("内容が記載されていません。")
        return false;
      }
      return true;
    }
  var dateSelector = null;
  var categoryData= null;
  document.observe('dom:loaded',function(){
    var queryHash = window.location.search.parseQuery();
    dateSelector = new DateSelector('account','account_date',
      null,year,month,day,true);
    categoryData = new CategoryData('items_span',"init",category);
    $('account_price').select();
    });
  </script>
</body>
</html>
